package com.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mapper.UserMapper;
import com.pojo.dto.LoginDto;
import com.pojo.dto.RegisterDto;
import com.pojo.dto.UserDto;
import com.pojo.entity.User;
import com.service.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : 杨世博
 * @date: Created in 9:50 2023/6/3
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserDto login(LoginDto loginDto) {
        User user = userMapper.selectForLogin(loginDto.getUsername(), loginDto.getEmail(), loginDto.getPassword());
        UserDto userDto = new UserDto();
        if (user!=null){
            BeanUtils.copyProperties(user,userDto);
        }else {
            userDto = null;
        }
        return userDto;
    }

    @Override
    public void register(RegisterDto registerDto) {
        User user = new User();
        BeanUtils.copyProperties(user, registerDto);
        user.setMoney(0.0);
        user.setState(0);
        userMapper.insert(user);
    }
}
